package cn.yuan.xiaoyu.mainmodule.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.yuan.xiaoyu.R;
import cn.yuan.xiaoyu.caipumodule.activity.CaiPuActivity;
import cn.yuan.xiaoyu.calendarmodule.activity.CalendarActivity;
import cn.yuan.xiaoyu.chatmodule.service.DragFloatService;
import cn.yuan.xiaoyu.commonmodule.activity.BaseActivity;
import cn.yuan.xiaoyu.commonmodule.utils.StatusBarCompatUtils;
import cn.yuan.xiaoyu.donwloadmodule.activity.DownloadActivity;
import cn.yuan.xiaoyu.jokemodule.activity.JokeActivity;
import cn.yuan.xiaoyu.mainmodule.adapter.MainListAdapter;
import cn.yuan.xiaoyu.mainmodule.bean.MainListBean;
import cn.yuan.xiaoyu.mapmodule.activity.BaiduMapActivity;
import cn.yuan.xiaoyu.newsmodule.activity.NewsActivity;
import cn.yuan.xiaoyu.testmodule.activity.TestActivity;
import cn.yuan.xiaoyu.wangmodule.activity.WangWangActivity;

/**
 * Created by yukuoyuan on 2017/2/27.
 * 这是一个主界面
 */
public class MainActivity extends BaseActivity implements MainListAdapter.OnItemClicklistener {
    @Bind(R.id.tv_toolbar_title)
    TextView tvToolbarTitle;
    @Bind(R.id.rcv_main)
    RecyclerView rcvMain;
    @Bind(R.id.iv_avatar)
    ImageView ivAvatar;
    @Bind(R.id.iv_toolbar_right)
    ImageView ivToolbarRight;
    private Intent intent;


    @Override
    protected void bindPresenter() {
        rcvMain.setLayoutManager(new GridLayoutManager(this, 3));

    }

    @Override
    protected void initData(Bundle extras) {

        MainListAdapter mainListAdapter = new MainListAdapter(getMainData(), this);
        rcvMain.setAdapter(mainListAdapter);
        mainListAdapter.notifyDataSetChanged();
        mainListAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Intent intent = new Intent(MainActivity.this, DragFloatService.class);
        //启动FloatViewService
        startService(intent);
    }

    @Override
    protected void onPause() {
        super.onPause();
        // 销毁悬浮窗
        // Intent intent = new Intent(MainActivity.this, DragFloatService.class);
        //终止FloatViewService
        //stopService(intent);
    }

    /**
     * 获取主界面列表数据
     *
     * @return
     */
    public List<MainListBean> getMainData() {
        List<MainListBean> listBeen = new ArrayList<>();
        MainListBean jokebean = new MainListBean();
        jokebean.img = R.drawable.main_joke;
        jokebean.name = "笑话大全";
        jokebean.type = 1;
        listBeen.add(jokebean);
        MainListBean downloadbean = new MainListBean();
        downloadbean.img = R.drawable.main_download;
        downloadbean.name = "下载管理";
        downloadbean.type = 2;
        listBeen.add(downloadbean);
        MainListBean caipubean = new MainListBean();
        caipubean.img = R.drawable.main_caipu;
        caipubean.name = "菜谱大全";
        caipubean.type = 3;
        listBeen.add(caipubean);
        MainListBean calendarbean = new MainListBean();
        calendarbean.img = R.drawable.main_calendar;
        calendarbean.name = "日历汇总";
        calendarbean.type = 4;
        listBeen.add(calendarbean);
        MainListBean mapbean = new MainListBean();
        mapbean.img = R.drawable.main_map;
        mapbean.name = "百度地图";
        mapbean.type = 5;
        listBeen.add(mapbean);
        MainListBean wangbean = new MainListBean();
        wangbean.img = R.drawable.main_wang;
        wangbean.name = "旺旺";
        wangbean.type = 6;
        listBeen.add(wangbean);
        MainListBean newsbean = new MainListBean();
        newsbean.img = R.drawable.main_news;
        newsbean.name = "新闻";
        newsbean.type = 7;
        listBeen.add(newsbean);
        return listBeen;
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this);
        tvToolbarTitle.setVisibility(View.VISIBLE);
        ivAvatar.setVisibility(View.VISIBLE);
        tvToolbarTitle.setText("测试主界面");
        ivAvatar.setImageResource(R.drawable.main_account);
    }


    @Override
    public void onItemClick(int type) {
        switch (type) {
            case 1:
                intent = new Intent(this, JokeActivity.class);
                startActivity(intent);
                break;
            case 2:
                intent = new Intent(this, DownloadActivity.class);
                startActivity(intent);
                break;
            case 3:
                intent = new Intent(this, CaiPuActivity.class);
                startActivity(intent);
                break;
            case 4:
                intent = new Intent(this, CalendarActivity.class);
                startActivity(intent);
                break;
            case 5:
                intent = new Intent(this, BaiduMapActivity.class);
                startActivity(intent);
                break;
            case 6:
                intent = new Intent(this, WangWangActivity.class);
                startActivity(intent);
                break;
            case 7:
                intent = new Intent(this, NewsActivity.class);
                startActivity(intent);
                break;
        }
    }

    @OnClick({R.id.iv_avatar, R.id.iv_toolbar_right})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_avatar:
                intent = new Intent(this, TestActivity.class);
                startActivity(intent);
                break;
            case R.id.iv_toolbar_right:
                break;
        }
    }
}
